
#ifndef THREAD_H_
#define THREAD_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <pthread.h>

struct aeEventLoop;
struct dict;
struct eventMsgqueue;
struct session;
struct fastArray;

typedef enum eventType {
	FILEREADEVENT_TYPE		=	0,
	SENDEVENT_TYPE			=	1,
	STOPEVENT_TYPE			=	2,
	DESTROYSESSION_TYPE	=	3
} eventType;

typedef enum threadState {
	INIT_THREADSTATE			=	0,
	START_THREADSTATE	=	1,
	STOP_THREADSTATE		=	2,
	STOPING_THREADSTATE	=3
} threadState;

typedef struct msgQueueEvent {
	enum eventType eventType;
	void* privateData;
} msgQueueEvent;

typedef struct thread {
	int threadId;
	enum threadState threadState;
	struct aeEventLoop* threadEventLoop;    //线程所在的事件循环
	struct eventMsgqueue* threadEventQueue;
	//struct dict* sessionDict;
	struct fastArray* sessionArray;
	pthread_t threadPid;
} thread;

struct thread* initThread();
void destroyThread(struct thread* t);
void stopThread(struct thread* t);

void sendMsgInThread(struct session* session, char* sendBuf, int sendBufLen);
int pushMsgQueueEvent(struct thread* t, struct session* session);
void stopThreadEvent(struct thread* t);
void destroySessionEvent(struct thread* t, struct session* session);

#ifdef __cplusplus
}
#endif

#endif /* THREAD_H_ */
